package com.miao.api;

import com.miao.dto.UserDTO;
import com.miao.service.IUserService;
import com.miao.util.JSONResponse;
import com.miao.util.RSAUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author miao
 * @since 2025-06-03
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping("/publicKey")
    public JSONResponse getPublicKey(){
        String publicKey = RSAUtil.getPublicKeyStr();
        return JSONResponse.ok(publicKey);
    }


    @PostMapping("/regist")
    public JSONResponse regist(@RequestBody UserDTO userDTO) throws Exception{
        userService.regit(userDTO);
        return JSONResponse.ok();
    }

    @PostMapping("/login")
    public JSONResponse login(@RequestBody UserDTO userDTO) throws Exception{
        String token = userService.login(userDTO);
        return JSONResponse.ok(token);
    }

}
